//
//  ViewController1.m
//  CivilianTravel
//
//  Created by 许仕杰 on 16/7/14.
//  Copyright © 2016年 许仕杰. All rights reserved.
//

#import "ViewController1.h"
#import "TourParticularsViewController.h"
#import "TourTableViewCell.h"
#import "TourModel.h"
@interface ViewController1 ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *messageArray;
@property (nonatomic, strong)NSMutableSet *set;

@end

@implementation ViewController1
- (NSMutableSet *)set{
    if (!_set) {
        _set = [NSMutableSet set];
    }
    return _set;
}

- (NSMutableArray *)messageArray{
    if (!_messageArray) {
        _messageArray = [NSMutableArray array];
    }
    return _messageArray;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView registerNib:[UINib nibWithNibName:@"TourTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:self.tableView];
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Students.plist" ofType:nil];
    NSMutableArray *array1 = [NSMutableArray array];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:filePath];
    for (NSString *liter in dic) {
        NSArray *array = dic[liter];
        for (NSDictionary *content in array) {
            TourModel *model = [[TourModel alloc] init];
            [model setValuesForKeysWithDictionary:content];
            [array1 addObject:model];
        }
    }
    for (TourModel *model in array1) {
        [self.set addObject:model];
    }
    for (TourModel *model in self.set) {
        [self.messageArray addObject:model];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.messageArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TourTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    TourModel *model = self.messageArray[indexPath.row];
    cell.name.text = model.name;
    cell.content.text = model.phone.description;
    cell.imageV.image = [UIImage imageNamed:model.imageName];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    TourParticularsViewController *tourParticulars = [[TourParticularsViewController alloc] initWithNibName:@"TourParticularsViewController" bundle:nil];
    [self.navigationController pushViewController:tourParticulars animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}



@end
